%{
#include <stdio.h>
#include <string.h>

void yyerror(const char *str){
	fprintf(stderr,"error: %s\n",str);
}

int yywrap(){
	return 1;
}

main(){
	yyparse();
}

%}

%union {
	int ival;
	float fval;
	char *sval;
}
%token CHARACTER
%token DIGIT
%token SIMBOL
%token QUOTE
%token MINUS
%token PLUS
%token MULTIPLY
%token DIVIDE
%token ASSIGN
%token NOT
%token GREATERTHAN
%token LESSTHAN
%token OBRACKET
%token EBRACKET
%token OSQBRACKET
%token ESQBRACKET
%token ROUNDEVEN
%token WHILE
%token ENDWHILE
%token IF
%token ELSE
%token ENDIF
%token OUT
%token OUTER
%token DOT
%token COMMA
%token OR
%token AND
%token COLLON
%token REAL
%token INT
%token FLOAT
%token STRING
%token DO
%token END
%token DECLARE
%token ENDDECLARE
%token OTHER
%token ENDL

%%


PROGRAMA:
	PROGRAMA SENTENCIA
	| SENTENCIA
	;

SENTENCIA:
	ASSIGN
	| ITER
	| DECISION
	| DECLARACION
	| PRINT
	;

ASIGNACION:
	ID ASSIGN EXP { printf("ASIGNACION\n"); }
	;

ITER:
	WHILE CONDICION DO PROGRAMA ENDWHILE
	;

DECISION:
	IF CONDICION DO PROGRAMA ENDIF
	| IF CONDICION DO PROGRAMA ELSE PROGRAMA ENDIF
	| DO CASE LISTACASE END CASE
	| DO CASE LISTACASE OTHER PROGRAMA END CASE
	;

LISTACASE:
	LISTACASE CASE
	| CASE
	;

CASE:
	CASE COMP PROGRAMA
	;

CONDICION:
	COMP AND COMP
	| COMP OR COMP
	| COMP
	| NOT COMP
	;

COMP:
	EXP COMPARADOR EXP
	;

EXP:
	EXP PLUS TERMINO
	| EXP MINUS TERMINO
	| TERMINO
	;

TERMINO:
	TERMINO MULTIPLY FACTOR
	| TERMINO DIVIDE FACTOR
	| FACTOR
	;

FACTOR:
	ID
	| CTE
	| OBRACKET EXP EBRACKET
	| REDONDEOPAR
	;

PRINT:
	OUT OBRACKET CTESTR EBRACKET
	| OUT OBRACKET ID EBRACKET
	;

DECLARACION:
	DECLARE TIPODATO COLLON OSQBRACKET LISTA_IDS ESQBRACKET ENDDECLARE
	;

LISTA_IDS:
	ID COMMA LISTA_ID
	;

LISTA_ID:
	ID
	;

TIPODATO:
	REAL
	| INT
	| STRING
	;

ID:	
	CHARACTER	{ printf("ID\n"); }
	| ID CHARACTER	{ printf("ID\n"); }
	| ID DIGIT	{ printf("ID\n"); }
	;

CTE:
	ENTERO DOT ENTERO
	| DOT ENTERO
	| ENTERO DOT
	| ENTERO
	;

ENTERO:
	ENTERO DIGIT
	| DIGIT
	;

CTESTR:
	QUOTE TEXTO QUOTE
	;

TEXTO:
	TEXTO CHARACTER
	| TEXTO DIGIT
	| TEXTO SIMBOL
	| CHARACTER
	| DIGIT
	| SIMBOL
	;

REDONDEOPAR:
	ROUNDEVEN OBRACKET ID EBRACKET
	| ROUNDEVEN OBRACKET CTE EBRACKET
	;

COMPARADOR:
	LESSTHAN
	| GREATERTHAN
	| ASSIGN ASSIGN
	| NOT ASSIGN
	;
